Search


📜 [專欄新文章] Solidity Weekly #19
✍️ mingd...

  • Share this:


📜 [專欄新文章] Solidity Weekly #19
✍️ mingderwang
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium

v0.5.0 改版說明

幾天前,Solidity Version 0.5.0 正式 released。這次大改版主要變動還是以安全為主,語言本身改為需用比較明確的宣告,edge-cases 問題拿掉,且提供更簡單的低階 compiler 介面。

其實這次可以說是累積了相當多的改變,做一次定版。詳細的改版文件可參考 “Solidity v0.5.0 Breaking Changes”,他會有些範例可參考。也可以看 changelog 簡單的更改清單。

如果要升級你的舊程式到 v0.5.0,需要改變的地方如下:(翻譯至 changelog)

.call() 改寫成 .call(““) 或 .call(signature, a, b, c) 改寫成 .call(abi.encodeWithSignature(signature, a, b, c)),且後者只支援 value types。

keccak256(a, b, c) 改寫成 keccak256(abi.encodePacked(a, b, c)) (原理說明可參考 Solidity Weekly #10)

所有 fallback 或 interface function 要宣告成 external,其他每個 function 都要宣告成 public。(各種宣告方式,可參考 Solidity Weekly #12)

所有變數,都要明確宣告其 data location。例如 uint[] x = m_x 要改成 uint[] storage x = m_x,宣告 x 的 data location 是 storage。特別要注意, external function 的變數,必須用 calldata 的 data location 型態。

合約 address 要執行功能前,須先明確轉換成 address type,才能執行其 functions,例如 c 是合約,以前可以寫 c.transfer(…), 現在必須改成 address(c).transfer(…)

如果你要做 transfer,尤其是 function 的變數,要先宣告成 address payable。

其他還蠻多變動的, 請詳見 Solidity v0.5.0 文件。

Solidity Weekly #19 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.

👏 歡迎轉載分享鼓掌


Tags:

About author
not provided
We have regular meeting twice per month on discussing blockchain technology, smart contracts and DApps development! We would love to have you join us!
View all posts